package com.chenfan.ccp.autoconfigure;

import com.chenfan.ccp.monitor.MonitorConfig;
import com.chenfan.ccp.annotation.NativeServletEnv;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 业务监控的注册
 */

@Configuration
@AutoConfigureAfter({PrometheusMetricsExportAutoConfiguration.class})
@ConditionalOnProperty(
        prefix = "management.metrics.export.prometheus",
        name = {"enabled"},
        havingValue = "true",
        matchIfMissing = true
)

public class GlobalMoniotrAutoConfigure extends AbstractAutoConfigure {

    @Bean
    @NativeServletEnv
    public MonitorConfig monitorConfig(PrometheusMeterRegistry prometheusMeterRegistry, PrometheusPushGatewayManager prometheusPushGatewayManager) {
        return new MonitorConfig(prometheusMeterRegistry, prometheusPushGatewayManager);

    }

}
